<script setup>
import { getBannerAPI } from "@/apis/banner";
import { onMounted, ref } from "vue";

const list = ref([]);

const getbanner = async () => {
  const res = await getBannerAPI();
  list.value = res.data;
  list.value.forEach((item) => {
    item.picture_src = `http://113.46.151.113:8000${item.picture_src}`;
  });
};

onMounted(() => getbanner());
</script>

<template>
  <div class="use-banner">
    <el-carousel height="500px">
      <el-carousel-item v-for="item in list" :key="item.id">
        <a :href="item.content_link" target="_blank">
          <img :src="item.picture_src" height="100%" width="100%" alt="" />
        </a>
        <div class="carousel-caption">
          <h3>{{ item.title }}</h3>
        </div>
      </el-carousel-item>
    </el-carousel>
  </div>
</template>

<style scoped lang="scss">
.use-banner {
  position: relative;
  width: 100%;
  text-align: center;
}

.el-carousel {
  margin: 0 auto;
}

.el-carousel-item img {
  object-fit: contain;
}

.carousel-caption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  padding: 15px;
  text-align: center;
  z-index: 10;
}
</style>
